home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-04-21 | 13.3 KB | 513 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: DrawFacet.cpp
- // Release Version: $ 1.0d1 $
- //
- // Author: Henri Lamiraux
- // Creation Date: 3/28/94
- //
- // Copyright: © 1993, 1994 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #ifndef DRAWFACET_H
- #include "DrawFacet.h"
- #endif
-
- #ifndef DRAWPART_H
- #include "DrawPart.h"
- #endif
-
- #ifndef DRAWSELECTION_H
- #include "DrawSelection.h"
- #endif
-
- #ifndef SHAPES_H
- #include "Shapes.h"
- #endif
-
- #ifndef DRAWFRAME_H
- #include "DrawFrame.h"
- #endif
-
- // ----- Framework Includes -----
-
- #ifndef FWUTIL_H
- #include "FWUtil.h"
- #endif
-
- #ifndef FWFRMING_H
- #include "FWFrming.h"
- #endif
-
- // ----- OPF Foundation Includes -----
-
- #ifndef BCOLL_H
- #include <BCColl.h>
- #endif
-
-
- // ----- Graphix Includes -----
-
- #ifndef FWGCONST_H
- #include "FWGConst.h"
- #endif
-
- #ifndef FWSTYLE_H
- #include "FWStyle.h"
- #endif
-
- #ifndef FWDFAULT_H
- #include "FWDFault.h"
- #endif
-
- #ifndef FWTXTSHP_H
- #include "FWTxtShp.h"
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef _TRNSFORM_
- #include <Trnsform.h>
- #endif
-
- #ifndef _XMPSESSN_
- #include <XMPSessM.h>
- #endif
-
- #ifndef _DISPTCH_
- #include <Disptch.h>
- #endif
-
- // ----- Macintosh Includes -----
-
- #if defined(FW_BUILD_MAC) && !defined(__EVENTS__)
- #include <Events.h> // GetMouse, StillDown.
- #endif
-
- #if defined(FW_BUILD_MAC) && !defined(__QUICKDRAW__)
- #include <Quickdraw.h>
- #endif
-
- #if defined(FW_BUILD_MAC) && !defined(__TOOLUTILS__)
- #include <ToolUtils.h>
- #endif
-
- #if defined(FW_BUILD_MAC) && !defined(__LIMITS__)
- #include <limits.h>
- #endif
-
- #if defined(FW_BUILD_MAC) && !defined(__STDLIB__)
- #include <StdLib.h>
- #endif
-
- #if defined(FW_BUILD_MAC) && !defined(__DRAG__)
- #include <Drag.h>
- #endif
-
- #if defined(FW_BUILD_MAC) && !defined(mathRoutinesIncludes)
- #include <math routines.h>
- #endif
-
- #pragma segment drawpart
-
- //=========================================================================
- // CDrawFacet
- //=========================================================================
-
- //------------------------------------------------------------------------------
- // CDrawFacet::CDrawFacet
- //------------------------------------------------------------------------------
-
- CDrawFacet::CDrawFacet()
- {
- }
-
- //------------------------------------------------------------------------------
- // CDrawFacet::IDrawFacet
- //------------------------------------------------------------------------------
-
- void CDrawFacet::IDrawFacet(XMPFacet* xmpFacet, CDrawPart* drawPart)
- {
- InitFacet(xmpFacet);
- fDrawPart = drawPart;
- }
-
- //------------------------------------------------------------------------------
- // CDrawFacet::~CDrawFacet
- //------------------------------------------------------------------------------
-
- CDrawFacet::~CDrawFacet()
- {
- }
-
- //------------------------------------------------------------------------------
- // CDrawFacet::Draw
- //------------------------------------------------------------------------------
-
- void CDrawFacet::Draw(FW_CGraphicContext* gc)
- {
- XMPShape* clipShape = ::NewXMPShape();
- gc->GetClipShape(clipShape);
- XMPShape* svClipShape = ::NewXMPShape(clipShape);
-
- ::EraseRgn(clipShape->GetQDRegion());
-
- BC_TCollectionActiveIterator<CBaseShape*> ite(*fDrawPart->GetShapeList());
- while (!ite.IsDone())
- {
- (*ite.CurrentItem())->DrawShape(gc);
- ite.Next();
- }
-
- delete clipShape;
-
- DrawGrid(gc);
-
- gc->SetClipShape(svClipShape);
-
- // ----- Draw selections Handles -----
- if (GetFrame()->IsActive())
- {
- ((CDrawSelection*)fDrawPart->GetSelection())->DrawSelectionHandles(this, TRUE);
- }
-
- delete svClipShape;
-
- }
-
- //------------------------------------------------------------------------------
- // CDrawFacet::MouseEnterFrame
- //------------------------------------------------------------------------------
-
- void CDrawFacet::MouseEnter(const FW_CPoint& /*where*/)
- {
- if (fDrawPart->GetActiveFrame() != GetFrame() || fDrawPart->GetTool() == kSelectTool)
- ::InitCursor();
- else
- ::SetCursor(*::GetCursor(crossCursor));
- }
-
- //------------------------------------------------------------------------------
- // CDrawFacet::DoMouseDownInEmbeddedFrame
- //------------------------------------------------------------------------------
-
- FW_Boolean CDrawFacet::DoMouseDownInEmbeddedFrame(XMPFacet* embeddedXMPFacet,
- const FW_CPoint& where,
- XMPEventData event)
- {
- CDrawProxyRun *drawProxyRun = (CDrawProxyRun*)fDrawPart->XMPFrametoProxyRun(embeddedXMPFacet->GetFrame());
- if (drawProxyRun->IsSelected())
- {
- if (!::WaitMouseMoved(event->where))
- {
- drawProxyRun->SetSelectState(FALSE);
- event->what = mouseDown;
- fDrawPart->GetSession()->GetDispatcher()->Dispatch(event);
- if (GetFrame()->IsActive())
- {
- drawProxyRun->SetSelectState(TRUE);
- }
- return TRUE;
- }
- }
-
- return DoMouseDown(where, event);
- }
-
- //------------------------------------------------------------------------------
- // CDrawFacet::DoMouseDownInEmbeddedFrameBorder
- //------------------------------------------------------------------------------
-
- FW_Boolean CDrawFacet::DoMouseDownInEmbeddedFrameBorder(XMPFacet* embeddedXMPFacet,
- const FW_CPoint& where,
- XMPEventData event)
- {
- FW_UNUSED(embeddedXMPFacet);
-
- FW_CGraphicContext gc(*this);
-
- fDrawPart->SetTool(kSelectTool);
-
- CDrawProxyRun *drawProxyRun = (CDrawProxyRun*)fDrawPart->XMPFrametoProxyRun(embeddedXMPFacet->GetFrame());
- CProxyShape *theShape = drawProxyRun->GetShape();
- CDrawSelection* selection = (CDrawSelection*)fDrawPart->GetSelection();
-
- if (::TestShiftKey(event))
- {
- if (theShape->IsSelected())
- {
- selection->RemoveFromSelection(theShape, TRUE);
- return TRUE;
- }
- else
- selection->AddToSelection(theShape, TRUE);
-
- // ----- Clear the shift key flag
- event->modifiers -= 0x0200;
- }
- else if (!theShape->IsSelected())
- {
- selection->CloseSelection();
- selection->AddToSelection(theShape, TRUE);
- }
-
- // ----- if a shape is selected start dragging
- if (theShape->IsSelected())
- {
- FW_SPlatformPoint anchorPoint = where;
- short whichHandle = theShape->WhichHandle(this, anchorPoint);
- selection->SetAnchorShape(theShape);
- if (whichHandle != 0)
- selection->Resize(&gc, whichHandle, anchorPoint, event);
- else
- selection->Drag(this, event);
- }
-
- return TRUE;
- // return DoMouseDown(where, event);
-
- }
-
- //------------------------------------------------------------------------------
- // CDrawFacet::DoMouseDown
- //------------------------------------------------------------------------------
-
- FW_Boolean CDrawFacet::DoMouseDown(const FW_CPoint& where, XMPEventData event)
- {
- FW_CGraphicContext gc(*this);
-
- FW_SPlatformPoint anchorPoint = gc.AsPlatformPoint(where);
-
- if (fDrawPart->GetTool() == kSelectTool)
- {
- CDrawSelection* selection = (CDrawSelection*)fDrawPart->GetSelection();
-
- // ----- Click in an handle
- short whichHandle;
- CBaseShape* shape = selection->WhichHandle(this, anchorPoint, whichHandle);
- if (shape != NULL)
- {
- selection->SetAnchorShape(shape);
- selection->Resize(&gc, whichHandle, anchorPoint, event);
- fDrawPart->Changed();
- return TRUE;
- }
-
- // ----- if not in an handle, look for a shape
- shape = WhichShape(&gc, anchorPoint, event);
-
- // -----
- if (shape == NULL)
- {
- // ----- Draw a selection rectangle
- selection->SelectWithRectangle(this, anchorPoint, event);
- }
- else
- {
- if (::TestShiftKey(event))
- {
- if (shape->IsSelected())
- selection->RemoveFromSelection(shape, TRUE);
- else
- selection->AddToSelection(shape, TRUE);
- }
- else if (!shape->IsSelected())
- {
- selection->CloseSelection();
- selection->AddToSelection(shape, TRUE);
- }
-
- // ----- if a shape is selected start dragging
- if (shape->IsSelected())
- {
- selection->SetAnchorShape(shape);
- selection->Drag(this, event);
- fDrawPart->Changed();
- }
- }
-
- return TRUE;
- }
-
- CBaseShape *theShape = fDrawPart->NewShape(fDrawPart->GetTool() - kLine + kLineShape);
-
- FW_CStyle trackStyle(fDrawPart->GetPenSize());
-
- if (theShape->Track(&gc, trackStyle, anchorPoint, event))
- {
- FW_CColor fillColor, penColor;
- fDrawPart->GetFillColor(&fillColor);
- fDrawPart->GetPenColor(&penColor);
-
- FW_CInk brushInk(fillColor);
- FW_CStyle penStyle(fDrawPart->GetPenSize());
- FW_CInk penInk(penColor);
-
- theShape->SetBrushInk(brushInk); // We use the standard style for the brush
- theShape->SetPenStyle(penStyle);
- theShape->SetPenInk(penInk);
-
- theShape->SetFrameFillStyle(fDrawPart->GetFillFrame());
-
- fDrawPart->AddShape(theShape);
- fDrawPart->Changed();
-
- fDrawPart->ClipEmbeddedFrames(fDrawPart->GetMainPresentation());
- theShape->DrawShape(&gc);
-
- XMPShape *invalidShape = ::NewXMPShape();
- theShape->GetUpdateShape(invalidShape);
- this->InvalidateAllFacets(invalidShape, TRUE);
- delete invalidShape;
- }
- else
- {
- delete theShape;
- }
-
- return TRUE;
- }
-
- //------------------------------------------------------------------------------
- // CDrawFacet::WhichShape
- //------------------------------------------------------------------------------
-
- CBaseShape* CDrawFacet::WhichShape(FW_CGraphicContext* gc, FW_SPlatformPoint mouse, XMPEventData event)
- {
- BC_TCollectionActiveIterator<CBaseShape*> ite(*fDrawPart->GetShapeList());
- CBaseShape* shape;
- while (!ite.IsDone())
- {
- shape = *ite.CurrentItem();
- if (shape->HitTest(gc, mouse, event))
- return shape;
- ite.Next();
- }
-
- return NULL;
- }
-
- //------------------------------------------------------------------------------
- // CDrawFacet::DrawGrid
- //------------------------------------------------------------------------------
-
- void CDrawFacet::DrawGrid(FW_CGraphicContext* gc)
- {
- FW_CRect extend;
- ((CDrawFrame*)GetFrame())->GetExtendRect(&extend);
-
- char vertical[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF};
- char horizontal[8] = {0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01};
-
- FW_CLineShape line(FW_CPoint(ff(-1), 0), FW_CPoint(ff(-1), extend.bottom - ff(1)));
- line->SetPattern(vertical);
-
- for (XMPCoordinate x = ff(-1); x <= extend.right; x += ff(72))
- {
- line->Draw(gc);
- line->MoveShape(ff(72), 0);
- }
-
- line->SetPattern(horizontal);
- line->SetLineStart(FW_CPoint(0, ff(-1)));
- line->SetLineEnd(FW_CPoint(extend.right - ff(1), ff(-1)));
-
- for (XMPCoordinate y = ff(-1); y <= extend.bottom; y += ff(72))
- {
- line->Draw(gc);
- line->MoveShape(0, ff(72));
- }
- }
-
- //------------------------------------------------------------------------------
- // CDrawFacet::ClipEmbeddedFacets
- //------------------------------------------------------------------------------
-
- void CDrawFacet::ClipEmbeddedFacets()
- {
- XMPFacet* xmpFacet = GetXMPFacet();
-
- XMPShape* clipShape = ::NewXMPShape();
- XMPTransform* wclipTrans = ::NewXMPTransform();
-
- XMPShape* workingClip = ::NewXMPShape(GetClipShape());
- workingClip->Transform(GetWindowFrameTransform()); // so now in window coordinate
-
- BC_TCollectionActiveIterator<CBaseShape*> ite(*fDrawPart->GetShapeList());
- CBaseShape* shape;
- while (!ite.IsDone())
- {
- shape = *ite.CurrentItem();
- if (shape->GetShapeType() == kProxyShape)
- {
- BC_TCollectionActiveIterator<FW_CProxyFrame*> ite2(*((CProxyShape*)shape)->GetProxyRun()->GetProxyFrameList());
- FW_CProxyFrame* proxyFrame;
- while (!ite2.IsDone())
- {
- proxyFrame = *ite2.CurrentItem();
- if (proxyFrame->GetContainingFrame() == (FW_CEmbeddingFrame*)this->GetFrame())
- {
- XMPFrameFacetIterator ite3(proxyFrame->GetXMPFrame());
- for (XMPFacet *embeddedXMPFacet = ite3.First(); ite3.IsNotComplete(); embeddedXMPFacet = ite3.Next())
- {
- if (embeddedXMPFacet->GetContainingFacet() == xmpFacet)
- {
- XMPShape* embeddedClip = ::NewXMPShape(embeddedXMPFacet->GetFrame()->GetFrameShape());
- embeddedClip->Intersect(embeddedXMPFacet->GetFrame()->GetUsedShape());
-
- // ----- Transform workingClip into embeddedXMPFacet frame coordinate -----
- wclipTrans->CopyFrom(embeddedXMPFacet->GetWindowFrameTransform());
- wclipTrans->Invert();
- workingClip->Transform(wclipTrans);
-
- // ----- Set the clip of embeddedXMPFacet -----
- embeddedClip->Intersect(workingClip);
- workingClip->Subtract(embeddedClip);
- embeddedXMPFacet->ChangeGeometry(embeddedClip, NULL);
-
- // ----- put back workingClip to window coordinate
- wclipTrans->Invert();
- workingClip->Transform(wclipTrans);
- }
- }
- }
- ite2.Next();
- }
- }
- else
- {
- // ----- remove the clipShape of the shape -----
- FW_CGraphicContext gc(*this);
- clipShape->CopyFrom(shape->GetClipShape(&gc));
- clipShape->Transform(GetWindowContentTransform()); // in window coordinate
- workingClip->Subtract(clipShape);
- }
- ite.Next();
- }
-
- delete clipShape;
- delete workingClip;
- delete wclipTrans;
- }
-
- //------------------------------------------------------------------------------
- // CDrawFacet::CreateEmbeddedFacet
- //------------------------------------------------------------------------------
- // We need to set the selected flag in the newly created embedded facet
-
- XMPFacet* CDrawFacet::CreateEmbeddedFacet(FW_CProxyFrame *itsFrame, XMPShape* clipShape, XMPTransform* externalTransform,
- XMPFacet* siblingFacet, XMPFramePosition position)
- {
- XMPFacet* embeddedXMPFacet = FW_CFacet::CreateEmbeddedFacet(itsFrame,
- clipShape,
- externalTransform,
- siblingFacet,
- position);
-
- embeddedXMPFacet->SetSelected(itsFrame->GetProxyRun()->IsSelected());
-
- return embeddedXMPFacet;
- }
-
-